package com.hutu.controller.biz.admin.system;


import com.hutu.entity.system.Staff;
import com.hutu.model.resp.ResponseVo;
import com.hutu.service.system.StaffRoleService;
import com.hutu.service.system.StaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 *  后台用户管理
 *
 * @author admin
 * @since 2022-01-27
 */
@RestController
@RequestMapping("/admin/staff")
@Api(tags = "后台用户管理")
public class StaffController {

    @Resource
    private StaffService staffService;

    @Resource
    private StaffRoleService staffRoleService;

    @ApiOperation("新增")
    @PostMapping
    public ResponseVo add(@RequestBody Staff staff){
        return this.staffService.add(staff);
    }

    @ApiOperation("逻辑删除")
    @DeleteMapping("/{id}")
    public ResponseVo deleteById(@PathVariable Integer id){
        return this.staffService.deleteById(id);
    }

    @ApiOperation("批量逻辑删除")
    @DeleteMapping("/batch/{ids}")
    public ResponseVo deleteBatch(@PathVariable List<Integer> ids){
        return this.staffService.deleteBatch(ids);
    }

    @ApiOperation("编辑更新")
    @PutMapping
    public ResponseVo edit(@RequestBody Staff staff){
        return this.staffService.edit(staff);
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    public ResponseVo findById(@PathVariable Integer id){
        return this.staffService.findById(id);
    }

    @ApiOperation("多条件分页查询")
    @PostMapping("/page")
    public ResponseVo list(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size, @RequestBody Staff staff){
        return this.staffService.list(current, size, staff);
    }


    @ApiOperation("数据导入接口")
    @PostMapping("/import")
    public ResponseVo imp(MultipartFile file) throws IOException {
        return this.staffService.imp(file);
    }

    @ApiOperation("为后台用户设置角色")
    @PostMapping("/role/{staffId}")
    public ResponseVo setRole(@PathVariable Integer staffId, @RequestBody List<Integer> roleIds){
        return this.staffRoleService.setRole(staffId, roleIds);
    }

    @ApiOperation("得到后台用户的角色")
    @GetMapping("/role/{staffId}")
    public ResponseVo getRole(@PathVariable Integer staffId){
        return this.staffRoleService.getRole(staffId);
    }


    @ApiOperation("检查后台用户的密码")
    @GetMapping("/check/{pwd}/{id}")
    public ResponseVo checkPassword(@PathVariable String pwd,@PathVariable Integer id){
        return this.staffService.checkPassword(pwd,id);
    }

    @ApiOperation("更新密码")
    @PutMapping("/pwd")
    public ResponseVo updatePassword(@RequestBody Staff staff){
        return this.staffService.updatePassword(staff);
    }
}

